<template>
  <div>
    <h3>证书管理</h3>
    <el-table :data="certificates" border style="width: 100%">
      <el-table-column prop="name" label="证书名称" width="180"></el-table-column>
      <el-table-column prop="domain" label="域名"></el-table-column>
      <el-table-column prop="expirationDate" label="过期日期" width="180"></el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="editCertificate(scope.row)">编辑</el-button>
          <el-button type="text" size="small" @click="deleteCertificate(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button type="primary" size="small" @click="addCertificate">新增证书</el-button>
  </div>
</template>

<script>
export default {
  props: {
    siteId: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      certificates: [
        { id: 1, name: '证书A', domain: 'example.com', expirationDate: '2024-10-01' },
        { id: 2, name: '证书B', domain: 'test.com', expirationDate: '2025-10-01' }
      ]
    };
  },
  methods: {
    addCertificate() {
      this.$alert('新增证书功能待实现', '提示', {
        confirmButtonText: '确定'
      });
    },
    editCertificate(certificate) {
      this.$alert(`编辑证书 ${certificate.name}`, '提示', {
        confirmButtonText: '确定'
      });
    },
    deleteCertificate(certificate) {
      this.$confirm(`此操作将永久删除证书 ${certificate.name}, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.certificates = this.certificates.filter(c => c.id !== certificate.id);
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
};
</script>

<style scoped lang="scss">
h3 {
  margin-bottom: 20px;
}
</style>
